pip install pandas
Requirement already satisfied: pandas in c:\users\dell\anaconda3\lib\site-packages (1.1.3)Note: you may need to restart the kernel to use updated packages. Requirement already satisfied: pytz>=2017.2 in c:\users\dell\anaconda3\lib\site-packages (from pandas) (2020.1) Requirement already satisfied: numpy>=1.15.4 in c:\users\dell\anaconda3\lib\site-packages (from pandas) (1.19.2) Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\dell\anaconda3\lib\site-packages (from pandas) (2.8.1) Requirement already satisfied: six>=1.5 in c:\users\dell\anaconda3\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
%matplotlib inline
df = pd.read_csv("Desktop\Data Science\Dataset_.csv")
print(df)
Restaurant ID Restaurant Name Country Code City \
0 6317637 Le Petit Souffle 162 Makati City
1 6304287 Izakaya Kikufuji 162 Makati City
2 6300002 Heat - Edsa Shangri-La 162 Mandaluyong City
3 6318506 Ooma 162 Mandaluyong City
4 6314302 Sambo Kojin 162 Mandaluyong City
... ... ... ... ...
9546 5915730 Naml۱ Gurme 208 ��stanbul
9547 5908749 Ceviz A��ac۱ 208 ��stanbul
9548 5915807 Huqqa 208 ��stanbul
9549 5916112 A���k Kahve 208 ��stanbul
9550 5927402 Walter's Coffee Roastery 208 ��stanbul
Address \
0 Third Floor, Century City Mall, Kalayaan Avenu...
1 Little Tokyo, 2277 Chino Roces Avenue, Legaspi...
2 Edsa Shangri-La, 1 Garden Way, Ortigas, Mandal...
3 Third Floor, Mega Fashion Hall, SM Megamall, O...
4 Third Floor, Mega Atrium, SM Megamall, Ortigas...
... ...
9546 Kemanke�� Karamustafa Pa��a Mahallesi, R۱ht۱m ...
9547 Ko��uyolu Mahallesi, Muhittin ��st�_nda�� Cadd...
9548 Kuru�_e��me Mahallesi, Muallim Naci Caddesi, N...
9549 Kuru�_e��me Mahallesi, Muallim Naci Caddesi, N...
9550 Cafea��a Mahallesi, Bademalt۱ Sokak, No 21/B, ...
Locality \
0 Century City Mall, Poblacion, Makati City
1 Little Tokyo, Legaspi Village, Makati City
2 Edsa Shangri-La, Ortigas, Mandaluyong City
3 SM Megamall, Ortigas, Mandaluyong City
4 SM Megamall, Ortigas, Mandaluyong City
... ...
9546 Karak�_y
9547 Ko��uyolu
9548 Kuru�_e��me
9549 Kuru�_e��me
9550 Moda
Locality Verbose Longitude \
0 Century City Mall, Poblacion, Makati City, Mak... 121.027535
1 Little Tokyo, Legaspi Village, Makati City, Ma... 121.014101
2 Edsa Shangri-La, Ortigas, Mandaluyong City, Ma... 121.056831
3 SM Megamall, Ortigas, Mandaluyong City, Mandal... 121.056475
4 SM Megamall, Ortigas, Mandaluyong City, Mandal... 121.057508
... ... ...
9546 Karak�_y, ��stanbul 28.977392
9547 Ko��uyolu, ��stanbul 29.041297
9548 Kuru�_e��me, ��stanbul 29.034640
9549 Kuru�_e��me, ��stanbul 29.036019
9550 Moda, ��stanbul 29.026016
Latitude Cuisines ... Currency \
0 14.565443 French, Japanese, Desserts ... Botswana Pula(P)
1 14.553708 Japanese ... Botswana Pula(P)
2 14.581404 Seafood, Asian, Filipino, Indian ... Botswana Pula(P)
3 14.585318 Japanese, Sushi ... Botswana Pula(P)
4 14.584450 Japanese, Korean ... Botswana Pula(P)
... ... ... ... ...
9546 41.022793 Turkish ... Turkish Lira(TL)
9547 41.009847 World Cuisine, Patisserie, Cafe ... Turkish Lira(TL)
9548 41.055817 Italian, World Cuisine ... Turkish Lira(TL)
9549 41.057979 Restaurant Cafe ... Turkish Lira(TL)
9550 40.984776 Cafe ... Turkish Lira(TL)
Has Table booking Has Online delivery Is delivering now \
0 Yes No No
1 Yes No No
2 Yes No No
3 No No No
4 Yes No No
... ... ... ...
9546 No No No
9547 No No No
9548 No No No
9549 No No No
9550 No No No
Switch to order menu Price range Aggregate rating Rating color \
0 No 3 4.8 Dark Green
1 No 3 4.5 Dark Green
2 No 4 4.4 Green
3 No 4 4.9 Dark Green
4 No 4 4.8 Dark Green
... ... ... ... ...
9546 No 3 4.1 Green
9547 No 3 4.2 Green
9548 No 4 3.7 Yellow
9549 No 4 4.0 Green
9550 No 2 4.0 Green
Rating text Votes
0 Excellent 314
1 Excellent 591
2 Very Good 270
3 Excellent 365
4 Excellent 229
... ... ...
9546 Very Good 788
9547 Very Good 1034
9548 Good 661
9549 Very Good 901
9550 Very Good 591
[9551 rows x 21 columns]
display(df)
| Restaurant ID | Restaurant Name | Country Code | City | Address | Locality | Locality Verbose | Longitude | Latitude | Cuisines | ... | Currency | Has Table booking | Has Online delivery | Is delivering now | Switch to order menu | Price range | Aggregate rating | Rating color | Rating text | Votes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 6317637 | Le Petit Souffle | 162 | Makati City | Third Floor, Century City Mall, Kalayaan Avenu... | Century City Mall, Poblacion, Makati City | Century City Mall, Poblacion, Makati City, Mak... | 121.027535 | 14.565443 | French, Japanese, Desserts | ... | Botswana Pula(P) | Yes | No | No | No | 3 | 4.8 | Dark Green | Excellent | 314 |
| 1 | 6304287 | Izakaya Kikufuji | 162 | Makati City | Little Tokyo, 2277 Chino Roces Avenue, Legaspi... | Little Tokyo, Legaspi Village, Makati City | Little Tokyo, Legaspi Village, Makati City, Ma... | 121.014101 | 14.553708 | Japanese | ... | Botswana Pula(P) | Yes | No | No | No | 3 | 4.5 | Dark Green | Excellent | 591 |
| 2 | 6300002 | Heat - Edsa Shangri-La | 162 | Mandaluyong City | Edsa Shangri-La, 1 Garden Way, Ortigas, Mandal... | Edsa Shangri-La, Ortigas, Mandaluyong City | Edsa Shangri-La, Ortigas, Mandaluyong City, Ma... | 121.056831 | 14.581404 | Seafood, Asian, Filipino, Indian | ... | Botswana Pula(P) | Yes | No | No | No | 4 | 4.4 | Green | Very Good | 270 |
| 3 | 6318506 | Ooma | 162 | Mandaluyong City | Third Floor, Mega Fashion Hall, SM Megamall, O... | SM Megamall, Ortigas, Mandaluyong City | SM Megamall, Ortigas, Mandaluyong City, Mandal... | 121.056475 | 14.585318 | Japanese, Sushi | ... | Botswana Pula(P) | No | No | No | No | 4 | 4.9 | Dark Green | Excellent | 365 |
| 4 | 6314302 | Sambo Kojin | 162 | Mandaluyong City | Third Floor, Mega Atrium, SM Megamall, Ortigas... | SM Megamall, Ortigas, Mandaluyong City | SM Megamall, Ortigas, Mandaluyong City, Mandal... | 121.057508 | 14.584450 | Japanese, Korean | ... | Botswana Pula(P) | Yes | No | No | No | 4 | 4.8 | Dark Green | Excellent | 229 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 9546 | 5915730 | Naml۱ Gurme | 208 | ��stanbul | Kemanke�� Karamustafa Pa��a Mahallesi, R۱ht۱m ... | Karak�_y | Karak�_y, ��stanbul | 28.977392 | 41.022793 | Turkish | ... | Turkish Lira(TL) | No | No | No | No | 3 | 4.1 | Green | Very Good | 788 |
| 9547 | 5908749 | Ceviz A��ac۱ | 208 | ��stanbul | Ko��uyolu Mahallesi, Muhittin ��st�_nda�� Cadd... | Ko��uyolu | Ko��uyolu, ��stanbul | 29.041297 | 41.009847 | World Cuisine, Patisserie, Cafe | ... | Turkish Lira(TL) | No | No | No | No | 3 | 4.2 | Green | Very Good | 1034 |
| 9548 | 5915807 | Huqqa | 208 | ��stanbul | Kuru�_e��me Mahallesi, Muallim Naci Caddesi, N... | Kuru�_e��me | Kuru�_e��me, ��stanbul | 29.034640 | 41.055817 | Italian, World Cuisine | ... | Turkish Lira(TL) | No | No | No | No | 4 | 3.7 | Yellow | Good | 661 |
| 9549 | 5916112 | A���k Kahve | 208 | ��stanbul | Kuru�_e��me Mahallesi, Muallim Naci Caddesi, N... | Kuru�_e��me | Kuru�_e��me, ��stanbul | 29.036019 | 41.057979 | Restaurant Cafe | ... | Turkish Lira(TL) | No | No | No | No | 4 | 4.0 | Green | Very Good | 901 |
| 9550 | 5927402 | Walter's Coffee Roastery | 208 | ��stanbul | Cafea��a Mahallesi, Bademalt۱ Sokak, No 21/B, ... | Moda | Moda, ��stanbul | 29.026016 | 40.984776 | Cafe | ... | Turkish Lira(TL) | No | No | No | No | 2 | 4.0 | Green | Very Good | 591 |
9551 rows × 21 columns
df.describe()
| Restaurant ID | Country Code | Longitude | Latitude | Average Cost for two | Price range | Aggregate rating | Votes | |
|---|---|---|---|---|---|---|---|---|
| count | 9.551000e+03 | 9551.000000 | 9551.000000 | 9551.000000 | 9551.000000 | 9551.000000 | 9551.000000 | 9551.000000 |
| mean | 9.051128e+06 | 18.365616 | 64.126574 | 25.854381 | 1199.210763 | 1.804837 | 2.666370 | 156.909748 |
| std | 8.791521e+06 | 56.750546 | 41.467058 | 11.007935 | 16121.183073 | 0.905609 | 1.516378 | 430.169145 |
| min | 5.300000e+01 | 1.000000 | -157.948486 | -41.330428 | 0.000000 | 1.000000 | 0.000000 | 0.000000 |
| 25% | 3.019625e+05 | 1.000000 | 77.081343 | 28.478713 | 250.000000 | 1.000000 | 2.500000 | 5.000000 |
| 50% | 6.004089e+06 | 1.000000 | 77.191964 | 28.570469 | 400.000000 | 2.000000 | 3.200000 | 31.000000 |
| 75% | 1.835229e+07 | 1.000000 | 77.282006 | 28.642758 | 700.000000 | 2.000000 | 3.700000 | 131.000000 |
| max | 1.850065e+07 | 216.000000 | 174.832089 | 55.976980 | 800000.000000 | 4.000000 | 4.900000 | 10934.000000 |
df.head()
| Restaurant ID | Restaurant Name | Country Code | City | Address | Locality | Locality Verbose | Longitude | Latitude | Cuisines | ... | Currency | Has Table booking | Has Online delivery | Is delivering now | Switch to order menu | Price range | Aggregate rating | Rating color | Rating text | Votes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 6317637 | Le Petit Souffle | 162 | Makati City | Third Floor, Century City Mall, Kalayaan Avenu... | Century City Mall, Poblacion, Makati City | Century City Mall, Poblacion, Makati City, Mak... | 121.027535 | 14.565443 | French, Japanese, Desserts | ... | Botswana Pula(P) | Yes | No | No | No | 3 | 4.8 | Dark Green | Excellent | 314 |
| 1 | 6304287 | Izakaya Kikufuji | 162 | Makati City | Little Tokyo, 2277 Chino Roces Avenue, Legaspi... | Little Tokyo, Legaspi Village, Makati City | Little Tokyo, Legaspi Village, Makati City, Ma... | 121.014101 | 14.553708 | Japanese | ... | Botswana Pula(P) | Yes | No | No | No | 3 | 4.5 | Dark Green | Excellent | 591 |
| 2 | 6300002 | Heat - Edsa Shangri-La | 162 | Mandaluyong City | Edsa Shangri-La, 1 Garden Way, Ortigas, Mandal... | Edsa Shangri-La, Ortigas, Mandaluyong City | Edsa Shangri-La, Ortigas, Mandaluyong City, Ma... | 121.056831 | 14.581404 | Seafood, Asian, Filipino, Indian | ... | Botswana Pula(P) | Yes | No | No | No | 4 | 4.4 | Green | Very Good | 270 |
| 3 | 6318506 | Ooma | 162 | Mandaluyong City | Third Floor, Mega Fashion Hall, SM Megamall, O... | SM Megamall, Ortigas, Mandaluyong City | SM Megamall, Ortigas, Mandaluyong City, Mandal... | 121.056475 | 14.585318 | Japanese, Sushi | ... | Botswana Pula(P) | No | No | No | No | 4 | 4.9 | Dark Green | Excellent | 365 |
| 4 | 6314302 | Sambo Kojin | 162 | Mandaluyong City | Third Floor, Mega Atrium, SM Megamall, Ortigas... | SM Megamall, Ortigas, Mandaluyong City | SM Megamall, Ortigas, Mandaluyong City, Mandal... | 121.057508 | 14.584450 | Japanese, Korean | ... | Botswana Pula(P) | Yes | No | No | No | 4 | 4.8 | Dark Green | Excellent | 229 |
5 rows × 21 columns
df.tail()
| Restaurant ID | Restaurant Name | Country Code | City | Address | Locality | Locality Verbose | Longitude | Latitude | Cuisines | ... | Currency | Has Table booking | Has Online delivery | Is delivering now | Switch to order menu | Price range | Aggregate rating | Rating color | Rating text | Votes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 9546 | 5915730 | Naml۱ Gurme | 208 | ��stanbul | Kemanke�� Karamustafa Pa��a Mahallesi, R۱ht۱m ... | Karak�_y | Karak�_y, ��stanbul | 28.977392 | 41.022793 | Turkish | ... | Turkish Lira(TL) | No | No | No | No | 3 | 4.1 | Green | Very Good | 788 |
| 9547 | 5908749 | Ceviz A��ac۱ | 208 | ��stanbul | Ko��uyolu Mahallesi, Muhittin ��st�_nda�� Cadd... | Ko��uyolu | Ko��uyolu, ��stanbul | 29.041297 | 41.009847 | World Cuisine, Patisserie, Cafe | ... | Turkish Lira(TL) | No | No | No | No | 3 | 4.2 | Green | Very Good | 1034 |
| 9548 | 5915807 | Huqqa | 208 | ��stanbul | Kuru�_e��me Mahallesi, Muallim Naci Caddesi, N... | Kuru�_e��me | Kuru�_e��me, ��stanbul | 29.034640 | 41.055817 | Italian, World Cuisine | ... | Turkish Lira(TL) | No | No | No | No | 4 | 3.7 | Yellow | Good | 661 |
| 9549 | 5916112 | A���k Kahve | 208 | ��stanbul | Kuru�_e��me Mahallesi, Muallim Naci Caddesi, N... | Kuru�_e��me | Kuru�_e��me, ��stanbul | 29.036019 | 41.057979 | Restaurant Cafe | ... | Turkish Lira(TL) | No | No | No | No | 4 | 4.0 | Green | Very Good | 901 |
| 9550 | 5927402 | Walter's Coffee Roastery | 208 | ��stanbul | Cafea��a Mahallesi, Bademalt۱ Sokak, No 21/B, ... | Moda | Moda, ��stanbul | 29.026016 | 40.984776 | Cafe | ... | Turkish Lira(TL) | No | No | No | No | 2 | 4.0 | Green | Very Good | 591 |
5 rows × 21 columns
df.columns
Index(['Restaurant ID', 'Restaurant Name', 'Country Code', 'City', 'Address',
'Locality', 'Locality Verbose', 'Longitude', 'Latitude', 'Cuisines',
'Average Cost for two', 'Currency', 'Has Table booking',
'Has Online delivery', 'Is delivering now', 'Switch to order menu',
'Price range', 'Aggregate rating', 'Rating color', 'Rating text',
'Votes'],
dtype='object')
Task 1 : Explore the dataset and identify the number of rows and columns.
#Explore the dataset and identify the number of rows and columns.
df.shape
(9551, 21)
rows = df.shape[0]
columns = df.shape[1]
print("Rows: " + str(rows))
print("Columns: " + str(columns))
Rows: 9551 Columns: 21
The dataset has 9551 Rows and 21 Columns.
# Check for missing values in each column and handle them accordingly.
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 9551 entries, 0 to 9550 Data columns (total 21 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Restaurant ID 9551 non-null int64 1 Restaurant Name 9551 non-null object 2 Country Code 9551 non-null int64 3 City 9551 non-null object 4 Address 9551 non-null object 5 Locality 9551 non-null object 6 Locality Verbose 9551 non-null object 7 Longitude 9551 non-null float64 8 Latitude 9551 non-null float64 9 Cuisines 9542 non-null object 10 Average Cost for two 9551 non-null int64 11 Currency 9551 non-null object 12 Has Table booking 9551 non-null object 13 Has Online delivery 9551 non-null object 14 Is delivering now 9551 non-null object 15 Switch to order menu 9551 non-null object 16 Price range 9551 non-null int64 17 Aggregate rating 9551 non-null float64 18 Rating color 9551 non-null object 19 Rating text 9551 non-null object 20 Votes 9551 non-null int64 dtypes: float64(3), int64(5), object(13) memory usage: 1.5+ MB
There are 9 missing value in Cuisines Column.The number are very less compare to data. So either I can replace or remove. Here I remove 9 rows from the dataset.
df['Cuisines'].value_counts()
North Indian 936
North Indian, Chinese 511
Chinese 354
Fast Food 354
North Indian, Mughlai 334
...
Desserts, American 1
North Indian, South Indian, Chinese, Mithai, Fast Food 1
Chinese, Thai, Asian, Japanese, Korean, Seafood 1
Irish 1
Italian, Continental, Mexican, Lebanese 1
Name: Cuisines, Length: 1825, dtype: int64
df = df.dropna(axis=0)
df.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 9542 entries, 0 to 9550 Data columns (total 21 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Restaurant ID 9542 non-null int64 1 Restaurant Name 9542 non-null object 2 Country Code 9542 non-null int64 3 City 9542 non-null object 4 Address 9542 non-null object 5 Locality 9542 non-null object 6 Locality Verbose 9542 non-null object 7 Longitude 9542 non-null float64 8 Latitude 9542 non-null float64 9 Cuisines 9542 non-null object 10 Average Cost for two 9542 non-null int64 11 Currency 9542 non-null object 12 Has Table booking 9542 non-null object 13 Has Online delivery 9542 non-null object 14 Is delivering now 9542 non-null object 15 Switch to order menu 9542 non-null object 16 Price range 9542 non-null int64 17 Aggregate rating 9542 non-null float64 18 Rating color 9542 non-null object 19 Rating text 9542 non-null object 20 Votes 9542 non-null int64 dtypes: float64(3), int64(5), object(13) memory usage: 1.6+ MB
Now data is clean. There are no missing values in Dataset.
df.shape
(9542, 21)
# Perform data type conversion if necessary.
df.dtypes
Restaurant ID int64 Restaurant Name object Country Code int64 City object Address object Locality object Locality Verbose object Longitude float64 Latitude float64 Cuisines object Average Cost for two int64 Currency object Has Table booking object Has Online delivery object Is delivering now object Switch to order menu object Price range int64 Aggregate rating float64 Rating color object Rating text object Votes int64 dtype: object
df.iloc[0]
Restaurant ID 6317637 Restaurant Name Le Petit Souffle Country Code 162 City Makati City Address Third Floor, Century City Mall, Kalayaan Avenu... Locality Century City Mall, Poblacion, Makati City Locality Verbose Century City Mall, Poblacion, Makati City, Mak... Longitude 121.028 Latitude 14.5654 Cuisines French, Japanese, Desserts Average Cost for two 1100 Currency Botswana Pula(P) Has Table booking Yes Has Online delivery No Is delivering now No Switch to order menu No Price range 3 Aggregate rating 4.8 Rating color Dark Green Rating text Excellent Votes 314 Name: 0, dtype: object
# Analyze the distribution of the target variable ("Aggregate rating") and identify any class imbalances.
sns.distplot(df['Aggregate rating'],bins=35,rug=False,color="r",kde=True)
plt.show()
plt.hist(df['Aggregate rating'], edgecolor='black', bins=30)
plt.show()
From the above graph we can observe that most of the oservations has zero aggregate rating and we can tell from the remaining the dataset exhibit a Right-Skewed.
import math
from scipy.stats import shapiro
shapiro(df['Aggregate rating'])
ShapiroResult(statistic=0.7897467017173767, pvalue=0.0)
From the output we can see that the test statistic is 0.789 and the corresponding p-value is 0.0. Since the p-value is less than .05, we reject the null hypothesis of the Kolmogorov-Smirnov test. This means we have sufficient evidence to say that the sample data does not come from a normal distribution.
Task 2: Descriptive Analysis
# Calculate basic statistical measures (mean, median, standard deviation, etc.) for numerical columns.
Numeric_Columns = df.select_dtypes(include='number')
Numeric_Columns.describe()
| Restaurant ID | Country Code | Longitude | Latitude | Average Cost for two | Price range | Aggregate rating | Votes | |
|---|---|---|---|---|---|---|---|---|
| count | 9.542000e+03 | 9542.000000 | 9542.000000 | 9542.000000 | 9542.000000 | 9542.000000 | 9542.000000 | 9542.000000 |
| mean | 9.043301e+06 | 18.179208 | 64.274997 | 25.848532 | 1200.326137 | 1.804968 | 2.665238 | 156.772060 |
| std | 8.791967e+06 | 56.451600 | 41.197602 | 11.010094 | 16128.743876 | 0.905563 | 1.516588 | 430.203324 |
| min | 5.300000e+01 | 1.000000 | -157.948486 | -41.330428 | 0.000000 | 1.000000 | 0.000000 | 0.000000 |
| 25% | 3.019312e+05 | 1.000000 | 77.081565 | 28.478658 | 250.000000 | 1.000000 | 2.500000 | 5.000000 |
| 50% | 6.002726e+06 | 1.000000 | 77.192031 | 28.570444 | 400.000000 | 2.000000 | 3.200000 | 31.000000 |
| 75% | 1.835260e+07 | 1.000000 | 77.282043 | 28.642711 | 700.000000 | 2.000000 | 3.700000 | 130.000000 |
| max | 1.850065e+07 | 216.000000 | 174.832089 | 55.976980 | 800000.000000 | 4.000000 | 4.900000 | 10934.000000 |
#Explore the distribution of categorical variables like "Country Code", "City" and "Cuisines".
categorical_columns = ['Country Code','City',"Cuisines"]
for category in categorical_columns:
print('\nDistribution of ',category, ':')
print(df[category].value_counts())
sns.displot(df, x="Country Code", binwidth=20)
Distribution of Country Code :
1 8652
216 425
215 80
214 60
30 60
189 60
148 40
208 34
14 24
162 22
94 21
191 20
166 20
184 20
37 4
Name: Country Code, dtype: int64
Distribution of City :
New Delhi 5473
Gurgaon 1118
Noida 1080
Faridabad 251
Ghaziabad 25
...
Lincoln 1
Yorkton 1
Penola 1
Macedon 1
Beechworth 1
Name: City, Length: 140, dtype: int64
Distribution of Cuisines :
North Indian 936
North Indian, Chinese 511
Chinese 354
Fast Food 354
North Indian, Mughlai 334
...
Desserts, American 1
North Indian, South Indian, Chinese, Mithai, Fast Food 1
Chinese, Thai, Asian, Japanese, Korean, Seafood 1
Irish 1
Italian, Continental, Mexican, Lebanese 1
Name: Cuisines, Length: 1825, dtype: int64
<seaborn.axisgrid.FacetGrid at 0x21bf17e1eb0>
# Identify the top cuisines and cities with the highest number of restaurants.
Top_cuisines = df["Cuisines"].value_counts().head(15)
print(Top_cuisines)
North Indian 936 North Indian, Chinese 511 Chinese 354 Fast Food 354 North Indian, Mughlai 334 Cafe 299 Bakery 218 North Indian, Mughlai, Chinese 197 Bakery, Desserts 170 Street Food 149 Pizza, Fast Food 131 Chinese, Fast Food 118 Mithai, Street Food 116 South Indian 112 Bakery, Fast Food 108 Name: Cuisines, dtype: int64
Top_cities = df["City"].value_counts().head(15)
print(Top_cities)
New Delhi 5473 Gurgaon 1118 Noida 1080 Faridabad 251 Ghaziabad 25 Ahmedabad 21 Bhubaneshwar 21 Guwahati 21 Lucknow 21 Amritsar 21 Rio de Janeiro 20 Goa 20 Mangalore 20 Pretoria 20 London 20 Name: City, dtype: int64
Task 3 : Geospatial Analysis
#Visualize the locations of restaurants on a map using latitude and longitude information.
pip install folium
Requirement already satisfied: folium in c:\users\dell\anaconda3\lib\site-packages (0.17.0) Requirement already satisfied: numpy in c:\users\dell\anaconda3\lib\site-packages (from folium) (1.19.2) Requirement already satisfied: branca>=0.6.0 in c:\users\dell\anaconda3\lib\site-packages (from folium) (0.7.2) Requirement already satisfied: xyzservices in c:\users\dell\anaconda3\lib\site-packages (from folium) (2024.4.0) Requirement already satisfied: requests in c:\users\dell\anaconda3\lib\site-packages (from folium) (2.24.0) Requirement already satisfied: jinja2>=2.9 in c:\users\dell\anaconda3\lib\site-packages (from folium) (2.11.2) Requirement already satisfied: idna<3,>=2.5 in c:\users\dell\anaconda3\lib\site-packages (from requests->folium) (2.10) Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\dell\anaconda3\lib\site-packages (from requests->folium) (3.0.4) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\dell\anaconda3\lib\site-packages (from requests->folium) (1.25.11) Requirement already satisfied: certifi>=2017.4.17 in c:\users\dell\anaconda3\lib\site-packages (from requests->folium) (2020.6.20) Requirement already satisfied: MarkupSafe>=0.23 in c:\users\dell\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (1.1.1) Note: you may need to restart the kernel to use updated packages.
conda install folium -c conda-forge
Collecting package metadata (current_repodata.json): ...working... done Note: you may need to restart the kernel to use updated packages.
==> WARNING: A newer version of conda exists. <==
current version: 4.14.0
latest version: 24.5.0
Please update conda by running
$ conda update -n base -c conda-forge conda
Solving environment: ...working... done # All requested packages already installed. Retrieving notices: ...working... done
import folium
m = folium.Map(location=(45.5236, -122.6750))
# Calculate the map center
map_center = [df['Latitude'].mean(), df['Longitude'].mean()]
Restaurent = folium.Map(location=map_center, zoom_start=10)
# adding marker for each restaurants
for index, row in df.iterrows():
folium.Marker([row['Latitude'], row['Longitude']], popup=row['Restaurant Name']).add_to(Restaurent)
# Save the map as an HTML file
Restaurent.save('restaurant_map.html')
Restaurent
# Analyze the distribution of restaurants across different cities or countries.
city_counts = df['City'].value_counts()
# Count the number of restaurants in each country
country_counts = df['Country Code'].value_counts()
# Plot distribution by city
plt.figure(figsize=(12, 6))
city_counts.head(20).plot(kind='bar')
plt.title('Restaurant Distribution by City')
plt.xlabel('City')
plt.ylabel('Number of Restaurants')
plt.show()
# Plot distribution by country
plt.figure(figsize=(12, 6))
country_counts.head(20).plot(kind='bar')
plt.title('Restaurant Distribution by Country')
plt.xlabel('Country')
plt.ylabel('Number of Restaurants')
plt.show()
# Determine if there is any correlation between the restaurant's location and its rating.
# correaltions between age and sex columns
c = np.corrcoef(df["Latitude"],df["Aggregate rating"])
print('Correlations between location and rating\n',c)
Correlations between location and rating [[1.00000000e+00 1.96569018e-04] [1.96569018e-04 1.00000000e+00]]
sns.heatmap(df[['Latitude','Longitude','Aggregate rating']].corr(),annot=True)
<AxesSubplot:>